package com.inspur.edp.team.converter;

import com.inspur.edp.common.AbstractConverter;
import com.inspur.edp.common.CommonConstants;
import com.inspur.edp.team.domain.PaasTeamMember;
import com.inspur.edp.team.dto.TeamMember;
import io.iec.edp.caf.sysmanager.api.data.user.User;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.Map;

/**
 * 团队成员维护转换器类
 */
public class TeamMemberConverter extends AbstractConverter {

    public TeamMember convert2TeamMember(PaasTeamMember paasTeamMember, Map<String, User> userId2UserMap) {
        TeamMember teamMember = super.toTarget(paasTeamMember, TeamMember.class);
        teamMember.setCreatedTime(DateFormatUtils.format(paasTeamMember.getCreatedTime(), CommonConstants.DATE_FORMAT_PATTERN));
        teamMember.setLastModifiedTime(DateFormatUtils.format(paasTeamMember.getLastModifiedTime(), CommonConstants.DATE_FORMAT_PATTERN));
        teamMember.setRoleType(paasTeamMember.getRoleType() == null? 0: teamMember.getRoleType());
        teamMember.setUserCode(userId2UserMap.get(paasTeamMember.getUserId()).getCode());
        teamMember.setUserName(userId2UserMap.get(paasTeamMember.getUserId()).getName());
        return teamMember;
    }
}
